﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MathService.DSP.Signals.Noice
{
    public class WhiteNoiceSignal : DigitalSignal
    {
        /* -------------------------------------------------------------------------------------------- */

        protected Random f_Random = new Random(DateTime.Now.Millisecond);

        private double f_D = 1;

        private double f_M = 0;

        /* -------------------------------------------------------------------------------------------- */

        /// <summary>Дисперсия</summary>
        public double D { get { return f_D; } set { f_D = value; } }

        /// <summary>Мат.ожидание</summary>
        public double M { get { return f_M; } set { f_M = value; } }

        /// <summary>Случайное значение</summary>
        public double RandomSample { get { return ((f_Random.NextDouble() - 0.5) * f_D) + f_M; } }

        /* -------------------------------------------------------------------------------------------- */

        /// <summary>Случайный сигнал</summary>
        /// <param name="dx">Шаг дискретизации</param>
        /// <param name="Length">Длительность</param>
        /// <param name="D">Дисперсия</param>
        /// <param name="M">Мат.ожидание</param>
        public WhiteNoiceSignal(double dx, double Length, double D, double M)
            : base(dx, Length) { InitializeSignal(D, M); }

        protected virtual void InitializeSignal(double D, double M)
        {
            f_D = D;
            f_M = M;

            var lv_Samples = Samples;
            for(int i = 0, i_Length = lv_Samples.Length; i < i_Length; i++)
                lv_Samples[i] = RandomSample;                
        }

        /* -------------------------------------------------------------------------------------------- */



        /* -------------------------------------------------------------------------------------------- */
    }
}
